//
//  HXFeedBackViewController.m
//  HongxuanBluetooth
//
//  Created by 广州弘轩科技发展有限公司 on 2023/8/23.
//

#import "HXFeedBackViewController.h"

@interface HXFeedBackViewController ()<UITextViewDelegate>
@property(nonatomic,strong) UITextView *textView;
@property(nonatomic,strong) UILabel *placeholderLabel;
@end

@implementation HXFeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    self.fd_prefersNavigationBarHidden = YES;
    [self BottomFunction];
}
-(void)BottomFunction{
    
    UIImageView *tabr = [[UIImageView alloc] initWithFrame:CGRectMake(0, kNavHeight-44, winWidth, 44)];
    [self.view addSubview:tabr];
    UIImageView *mainscreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, winWidth, 44)];
    if([themeColors isEqualToString:@"default"]){
        mainscreen.image = [UIImage imageNamed:@"feedbackmain"];
        
    }else{
        mainscreen.image = [UIImage imageNamed:@"feedbackmid"];
    }

    [tabr addSubview:mainscreen];
    
    UIImageView *hintview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hint"]];
    [self.view addSubview:hintview];
    [hintview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(tabr.mas_bottom).offset(18);
        make.width.mas_equalTo(54.33);
        make.height.mas_equalTo(54.33);
        make.centerX.mas_equalTo(self.view);
    }];
    
    UILabel *title = [[UILabel alloc] init];
    title.text =@"If you have any questions or suggestions during use, you can quickly provide feedback to us on this";
    title.numberOfLines = 3;
    title.font = [UIFont systemFontOfSize:16];
    title.textColor = [UIColor whiteColor];
    [self.view addSubview:title];
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(hintview.mas_bottom).offset(13);
        make.width.mas_equalTo(330.33);
        make.height.mas_equalTo(60);
        make.centerX.mas_equalTo(self.view);
    }];
    
//    feedinputbox
    UIImageView *feedinputbox = [[UIImageView alloc] init];
    
//    feedinputbox.image = [UIImage imageNamed:@"feedinputbox"];
    feedinputbox.userInteractionEnabled = YES;
    [self.view addSubview:feedinputbox];
    [feedinputbox mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(title.mas_bottom).offset(25);
        make.width.mas_equalTo(314.33);
        make.height.mas_equalTo(288);
        make.centerX.mas_equalTo(self.view);
    }];
    
    
    self.textView = [[UITextView alloc]init];
    [feedinputbox addSubview:self.textView];
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-50);
    }];
    self.textView.delegate = self;
    
    //修复文本框是偏移（下移）
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    
    //设置文本
//    self.textView.text = @"我是UITextView，大家欢迎使用。";
    //设置文字对齐方式属性
    self.textView.textAlignment = NSTextAlignmentLeft;
    //设置文字对齐方
    //设置文字颜色属性
    self.textView.textColor = [UIColor whiteColor];
    //设置文字字体属性
    self.textView.font = [UIFont systemFontOfSize:16.0f];
    //设置编辑使能属性,是否允许编辑（=NO时，只用来显示，依然可以使用选择和拷贝功能）
    self.textView.editable = YES;
    
    //设置圆角、边框属性
//    self.textView.layer.cornerRadius = 6.0f;
//    self.textView.layer.borderWidth = 2;
//    self.textView.layer.borderColor = [[UIColor colorWithRed:200.0/255 green:50/255 blue:10/255 alpha:1] CGColor];
    
    //模仿UTextField的placeholder属性
//    self.placeholderLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, CGRectGetWidth(self.textView.frame), 20)];
    self.placeholderLabel = [[UILabel alloc]init];
    self.placeholderLabel.backgroundColor = [UIColor clearColor];
    self.placeholderLabel.textAlignment = NSTextAlignmentCenter;
    self.placeholderLabel.textColor = [UIColor whiteColor];
    self.placeholderLabel.text = @"Click to start writing";
    self.placeholderLabel.font = self.textView.font;
    [self.textView addSubview:self.placeholderLabel];
    [self.placeholderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.right.mas_equalTo(-5);
        make.top.mas_equalTo(120);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(314.33-20-10);
    }];
    if([themeColors isEqualToString:@"default"]){
        feedinputbox.image = [UIImage imageNamed:@"feedinputbox"];
        //设置背景颜色属性
        self.textView.backgroundColor = [UIColor blackColor];
        
    }else{
        feedinputbox.backgroundColor = midnightRGB;
        feedinputbox.layer.cornerRadius = 8;
        feedinputbox.layer.masksToBounds = YES;
        //设置背景颜色属性
        self.textView.backgroundColor = midnightRGB;
    }
    
    
    
//    feedimport
    UIImageView *feedimport = [[UIImageView alloc] init];
    feedimport.image = [UIImage imageNamed:@"feedimport"];
    [feedinputbox addSubview:feedimport];
    [feedimport mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-14);
        make.bottom.mas_equalTo(-17);
        make.width.mas_equalTo(34.67);
        make.height.mas_equalTo(34.33);
    }];
    
    UIImageView *feedsendtous = [[UIImageView alloc] init];
//    feedsendtousmid
    if([themeColors isEqualToString:@"default"]){
        feedsendtous.image = [UIImage imageNamed:@"feedsendtous"];
        
    }else{
        feedsendtous.image = [UIImage imageNamed:@"feedsendtousmid"];
    }
    
    feedsendtous.userInteractionEnabled = YES;
    [self.view addSubview:feedsendtous];
    [feedsendtous mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(feedinputbox.mas_bottom).offset(22);
        make.width.mas_equalTo(314.33);
        make.height.mas_equalTo(46.33);
        make.centerX.mas_equalTo(self.view);
        
    }];
    
    
    
    
    
    
    UIButton *sendtous = [UIButton buttonWithType:UIButtonTypeCustom];
    [sendtous setTitle:@"Send to us" forState:UIControlStateNormal];
    [sendtous setTitle:@"Send to us" forState:UIControlStateHighlighted];
    sendtous.titleLabel.font = [UIFont systemFontOfSize:25];
    [sendtous addTarget:self action:@selector(selectsendtous) forControlEvents:UIControlEventTouchUpInside];
    [feedsendtous addSubview:sendtous];
    [sendtous mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(feedsendtous);
        
    }];
    
    
    UIImageView *statebj = [[UIImageView alloc] init];
    if([themeColors isEqualToString:@"default"]){
        statebj.backgroundColor = [UIColor blackColor];
    }else{
        statebj.backgroundColor = midnightRGB;
    }
    [self.view addSubview:statebj];
    [statebj mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-34);
        make.height.mas_equalTo(50);
    }];
#pragma mark 返回入口
    UIImageView *backview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back"]];
    backview.userInteractionEnabled = YES;
    [self.view addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-37);
        make.width.mas_equalTo(33);
        make.height.mas_equalTo(36);
        make.left.mas_equalTo(26);
    }];
    
    UIButton *backbt = [UIButton buttonWithType:UIButtonTypeCustom];
    [backbt addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [backview addSubview:backbt];
    [backbt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(backview);
    }];
    
    UIImageView *bluetherview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bluether"]];
    bluetherview.userInteractionEnabled = YES;
    [self.view addSubview:bluetherview];
    [bluetherview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-52);
        make.height.mas_equalTo(13);
    }];
    
    
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    NSLog(@"将要开始编辑？");
    return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    NSLog(@"将要结束编辑？");
    return YES;
}

- (void)textViewDidBeginEditing:(UITextView *)textView{
    NSLog(@"开始编辑。");
    self.placeholderLabel.text = @"";
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    NSLog(@"结束编辑。");
    
    //模仿UTextField的placeholder属性
    if (self.textView.text.length == 0) {
        self.placeholderLabel.text = @"Click to start writing";
    }else{
        self.placeholderLabel.text = @"";
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSLog(@"将要改变内容？");
    
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView{
    NSLog(@"改变内容。");
}

- (void)textViewDidChangeSelection:(UITextView *)textView{
    NSLog(@"选中内容。");
}

#pragma mark- 按钮点击事件实现方法
- (void)btnClick:(UIButton*)sender{
    NSLog(@"添加内容：你好，我好，大家好！");
    
    self.textView.text = [self.textView.text stringByAppendingString:@"你好，我好，大家好！\n"];
    
    NSRange range = NSMakeRange([self.textView.text length]- 1, 1);
    [self.textView scrollRangeToVisible:range];
    
    [self.view endEditing:YES];
}

/*
 **监听点击事件，当点击非textfiled位置的时候，所有输入法全部收缩
 */
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [self.view endEditing:YES];
}
- (void)selectsendtous{
    NSLog(@"点击了selectsendtous");
    self.textView.text = @"";
}
-(void)back{
    
//    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
